package com.bblocks.common.anti_reptile.demo.controller;

import com.bblocks.common.anti_reptile.annotation.AntiReptile;
import com.bblocks.common.anti_reptile.constant.RuleResultEnum;
import com.bblocks.common.anti_reptile.demo.config.SpringContextUtils;
import com.bblocks.common.anti_reptile.rule.RuleActuator;
import com.bblocks.common.anti_reptile.util.ServletUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>Project: bb-anti-reptile - TestController</p>
 * <p>描述：测试用</p>
 *
 * @Author Zhao [125043150@qq.com]
 * @Date 2024/4/1 17:44
 * @Version 1.0
 * @since 8
 */
@RestController
@RequestMapping("/demo")
public class TestController {

    @AntiReptile
    @GetMapping("/xxx")
    public String xxx1() {
        return "Hello，World!";
    }

    @GetMapping("/xxx2")
    public String xxx2() {
        return "Hello，World2!";
    }

    @GetMapping("/xxx3")
    public String xxx3() {
        return "Hello，World3!";
    }

    @GetMapping("/reset")
    public String reset(Integer type) {
        RuleActuator ruleActuator = SpringContextUtils.getApplicationContext().getBean(RuleActuator.class);

        RuleResultEnum ruleResultEnum = RuleResultEnum.getRuleResult(type);
        ruleActuator.reset(ServletUtils.getRequest(),"/reset",ruleResultEnum);
        return "Ok!";
    }
}
